<?php

class Renderer
{
    public $additional_css;
    public $additional_js;
    
    public function __construct() 
    {
        $this->additional_css = array();
        if(APP_DEFAULT_CSS)
        {
            $this->additional_css = explode(",", APP_DEFAULT_CSS);
        }
        
        $this->additional_js = array();
        if(APP_DEFAULT_CSS)
        {
            $this->additional_js = explode(",", APP_DEFAULT_JS);
        }
        
        
        
    }
    
    public function addCss($css)
    {
        if(!in_array($css, $this->additional_css))
        {
            $this->additional_css[] = $css;

            if(DEBUG)
                echo "Add additional_css => ".$css;
        }
    }
    
    public function addJs($js)
    {
        if(!in_array($js, $this->additional_js))
        {
            $this->additional_js[] = $js;

            if(DEBUG)
                echo "Add additional_css => ".$js;
        }
    } 
        
    public function render($view, $datas = array())
    {
        $content = "";
        if(file_exists(CONF_VIEW.$view.".php"))
        {
            $renderer = $this;
            foreach ($datas as $key => $data)
            {
                $$key = $data;
            }
            ob_start();
            include_once CONF_VIEW.$view.".php";
            $content = ob_get_clean();
        }
        else
        {
           if(DEBUG)
            echo "View not exists => ".$view;
        }
        
        return $content;
    }
    
    public function js($filename)
    {
        return CONF_BASE.CONF_ASSETS_JS.$filename.".js";
    }
    
    public function img($filename)
    {
        return CONF_BASE.CONF_ASSETS_IMG.$filename;
    }
    
    public function css($filename)
    {
        return CONF_BASE.CONF_ASSETS_CSS.$filename.".css";
    }
    
    public function url($url)
    {
        return CONF_BASE.$url;
    }
}

?>
